if Http == nil then
    Http = {}
    Http.__index = Http
end

function Http:new( o )
    o = o or {}
    setmetatable( o, Http )
    return o
end

function Http:Init()
    Http.SVR_KEY = GetDedicatedServerKeyV2("tos")
    Http.SVR = "http://122.51.23.209:3000/"
    if IsInToolsMode() then
        Http.SVR = "http://localhost:3000/"
    end
    Http.Url={
        Player_GetPlayerInfo="player/getPlayerInfo",
        Player_SavePlayerInfo="player/savePlayerInfo",
        Log_Send="player/log"
    }
end


function Http:Post(url, data, callback)
    print("[HttpPost] url=",Http.SVR..url)
    local req = CreateHTTPRequestScriptVM("POST", Http.SVR..url)
    req:SetHTTPRequestHeaderValue("Content-Type", "application/json")
    req:SetHTTPRequestHeaderValue("Server-Key", Http.SVR_KEY)
    req:SetHTTPRequestGetOrPostParameter('data', json.encode(data))
    req:Send(function(res)
        --table.print(res)
        if res.StatusCode ~= 200 or not res.Body then
             print(Http.SVR .. url, " code:", res.StatusCode, res.Body)
            if callback then
                callback({success=false})
            end
            return
        end

        if callback then
            local result = json.decode(res.Body)
            if(result ~= nil) then
                callback(result)
            else
                callback({success=false})
            end
        end
    end)
end
